/*! Copyright(c) 2008-2012
 *
 *\file		Uart1.c
 *\brief		
 *\details	
 *
 *\author	Cai Peifeng
 *\version	
 *\date		18Jul12
 *
 *\warning	
 *
 *\history \arg	18Jul12, Cai Peifeng, Create the file
 */
#include "Uart1.h"

#define UART1_BAUD	38400

void Uart1_Init()
{
	UART1_DeInit();
	UART1_Init(UART1_BAUD, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,\
				UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
	UART1_ITConfig(UART1_IT_RXNE,ENABLE);
	UART1_Cmd(ENABLE);
}

void Uart1_SendByte(uint8_t data)
{
	UART1_SendData8(data);

	while( UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
	{
		
	}
}

void Uart1_SendString(uint8_t *data, uint16_t len)
{
	uint16_t i = 0;

	for( i = 0; i < len; i++)
	{
		Uart1_SendByte(*data);
		data++;
	}
}

uint8_t Uart1_ReceiveByte()
{
	uint8_t data;

	while( UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
	{
		
	}

	data = UART1_ReceiveData8();

	return data;
}